#pragma once

#include <windows.h>
#include "ILCommon.h"
#include "D3DHelper.h"
#include <d3d11.h>
#include <d3dx11.h>
#include <ctime>

#include "Terrain.h"
#include "Camera.h"
#include "Mouse.h"
#include "Unit.h"

#define m_pd3dContext (m_d3dHandles.pImmediateContext)
#define m_pd3dDevice (m_d3dHandles.pd3dDevice)
#define m_hWnd (m_WindowsHandles.hWnd)
#define m_pRenderTargetView (m_d3dHandles.pBBRenderTargetView)

class CILApp
{
public:
    HRESULT init(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
    int Run();
    HRESULT InitWindow( HINSTANCE hInstance, int nShowCmd, int width, int height );
    void Render();
    HRESULT InitD3D();
    void CleanupD3D();
    CCamera* GetCamera();
	HRESULT CreatePickingRenderTarget();
	void HandleMouseMessage( UINT message, WPARAM wParam, LPARAM lParam );
	void LeftMouseButtonDown(int x, int y);
	void MouseMove( int xPos, int yPos );
	
private:

    struct 
    {
        HINSTANCE hInst;
        HWND hWnd;
    } m_WindowsHandles;

    struct
    {
        ID3D11Device*				pd3dDevice;
        ID3D11DeviceContext*		pImmediateContext;
        IDXGISwapChain*				pSwapChain;
        ID3D11RenderTargetView*		pBBRenderTargetView;
		ID3D11RenderTargetView*		pPickRTView;
		ID3D11Texture2D*			pPickRT;
		ID3D11Texture2D*			pDS;
		ID3D11DepthStencilView*     pDSV;
        D3D_FEATURE_LEVEL featureLevel;
    }m_d3dHandles;
    
    UINT m_Width;
    UINT m_Height;

    CTerrain m_Terrain;
    CCamera m_Camera;
    clock_t m_time;
	CMouse m_Mouse;
	CD3DHelper* m_pD3DHelper;
	CUnit* pUnit;
};